package com.geilizu.dom.service.impl;

import com.geilizu.dom.dto.BuildingDto;
import com.geilizu.dom.dto.SearchDoAdminDto;
import com.geilizu.dom.dto.SearchDto;
import com.geilizu.dom.entity.Building;
import com.geilizu.dom.dao.BuildingDao;
import com.geilizu.dom.entity.Student;
import com.geilizu.dom.service.BuildingService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * (Building)表服务实现类
 *
 * @author makejava
 * @since 2022-07-12 16:59:03
 */
@Service("buildingService")
public class BuildingServiceImpl implements BuildingService {
    @Resource
    private BuildingDao buildingDao;

    @Override
    public List<Building> list() {
        return buildingDao.list();
    }

    @Override
    public boolean save(Building building) {
        return buildingDao.save(building);
    }

    @Override
    public Map<String, Object> list(Integer page, Integer size) {
        if (page == null || size == null || page < 0) {
            page = 0;
            size = 3;
        }
        page = (page - 1) * 3;
        List<BuildingDto> buildingList = buildingDao.queryAll(page, size);
        Long count = buildingDao.queryAllCount();
        Map<String, Object> map = new HashMap<>();
        map.put("buildingList", buildingList);
        map.put("count", count);
        return map;
    }

    @Override
    public Map<String, Object> search(SearchDto searchDto) {
        Integer page = (searchDto.getPage() - 1) * searchDto.getSize();
        List<Student> studentList = new ArrayList<>();
        Long count = Long.valueOf(0);
        if (searchDto.getKey().equals("introduction")) {
            SearchDoAdminDto searchDoAdminDto=new SearchDoAdminDto(page,searchDto.getSize(),searchDto.getValue(),"");
            studentList = buildingDao.search(searchDoAdminDto);
            count = buildingDao.searchCount(searchDoAdminDto);
        } else if (searchDto.getKey().equals("name")) {
            SearchDoAdminDto searchDoAdminDto=new SearchDoAdminDto(page,searchDto.getSize(),"",searchDto.getValue());
            studentList = buildingDao.search(searchDoAdminDto);
            count = buildingDao.searchCount(searchDoAdminDto);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("buildingList", studentList);
        map.put("count", count);
        return map;
    }
    @Override
    public Integer deleteById(Integer id) {
        return buildingDao.deleteById(id);
    }

    @Override
    public Integer updateById(Building building) {
        return buildingDao.updateById(building);
    }

    @Override
    public BuildingDto findById(Integer id) {
        System.out.println(id);

        return buildingDao.findById(id);
    }

}
